import { Controller, Inject, Get, Query, Body, Post, Put, Param, Del } from '@midwayjs/core';
import { RegionService } from '@service/system/region.service';
import { ListRegionDTO, CreateRegionDTO, UpdateRegionDTO } from '@dto/system/region.dto';
import { Auth } from '@decorator/auth.decorator';
import { Log, BusinessType } from '@decorator/log.decorator';

@Controller('/data/region')
export class RegionController {
  @Inject()
  regionService: RegionService;

  // 获取列表
  @Get('/list')
  async list(@Query() queryParams: ListRegionDTO) {
    return await this.regionService.list(queryParams);
  }

  // 新增
  @Auth('data:region:add')
  @Log({ title: '区域管理', businessType: BusinessType.ADD })
  @Post('/')
  async create(@Body() body: CreateRegionDTO) {
    return await this.regionService.create(body);
  }

  // 删除
  @Auth('data:region:remove')
  @Log({ title: '区域管理', businessType: BusinessType.REMOVE })
  @Del('/:regionId')
  async delete(@Param('regionId') regionId: string) {
    return await this.regionService.delete(regionId);
  }

  // 修改
  @Auth('data:region:edit')
  @Log({ title: '区域管理', businessType: BusinessType.EDIT })
  @Put('/')
  async update(@Body() body: UpdateRegionDTO) {
    return await this.regionService.update(body);
  }

  // 详情
  @Auth('data:region:query')
  @Get('/:regionId')
  async get(@Param('regionId') regionId: number) {
    return await this.regionService.detail(regionId);
  }

  // 外部接口新增（同步）
  @Auth('data:region:externalAdd')
  @Log({ title: '区域管理-同步外部', businessType: BusinessType.OTHER })
  @Post('/external/add')
  async externalAdd(@Body() body: { regionCode: string; regionName: string; parentId?: number; orderNum?: number; status?: string }) {
    return await this.regionService.createExternal(body);
  }
}


